<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*" pageEncoding="UTF-8" %>

<%@ page import="db_tool.*" %>
<%@ page import="tree_util.*" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    Account account = (Account) session.getAttribute("account");
    DbBean db = new DbBean();
    ArrayList<String> datas = db.executeRequest(account.getUsername(), account.getRoleName());
    session.setAttribute("datas", datas);
    String role = account.getRoleName();
    String agree;
    String show;
    boolean isgroup;
    if (role.equals("mentor")) {
        agree = "moniterAgree";
        show = "none";
        isgroup = false;
    } else {
        agree = "groupAgree";
        show = "block";
        isgroup = true;
    }


    String[] table = {"monitsite", "surface", "line", "dot", "waterupper", "watermiddle", "waterlow", "tool", "catches", "fish", "fishEgg"};
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="edge"/>
    <meta name="author" content="Daliu"/>
    <meta name="keywords" content="长江上游珍稀特有鱼类保护信息管理系统、长江上游、珍稀特有鱼类、保护信息"/>
    <meta name="describe" content="长江上游珍稀特有鱼类保护信息管理系统"/>
    <title>长江上游珍稀特有鱼类保护信息管理系统</title>
    <link href="css/register.css" rel="stylesheet"/>
    <link href="css/main.css" rel="stylesheet"/>
    <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>

</head>

<body>
<div class="article" id="article">
    <h3 class="useractive">&nbsp;&nbsp;申请审查</h3>
    <br>
    <table class="table" style="margin-bottom: 120px;">
        <tr>
            <th>请求用户名</th>
            <th>目标用户名</th>
            <th>请求数据类型</th>
            <th>是否同意</th>
        </tr>

        <%
            for (int i = 0; i < datas.size(); i++) {
                String[] colName = ((String) datas.get(i)).split(",");
                if (colName[4].equals("1") && colName[6].equals(account.getUsername())) continue;

        %>
        <tr>
            <td><%=colName[0]%>
            </td>
            <td><%=colName[1]%>
            </td>
            <td id="name"><span><%=colName[5]%></span></td>
            <td><label>同意 </label><input type="radio" name="<%=colName[5]%>" value="1" id="box"><label>
                不同意</label><input type="radio" name="<%=colName[5]%>" value="2" checked="checked" id="box"></td>
        </tr>
        <%}%>
        <%
            if (datas.size() != 0) {
        %>
        <tr>
            <td colspan="4">
                <button class="btn btn-primary sumbit" style="width: 120px;">提交</button>
            </td>
        </tr>
        <%}%>
    </table>
    <br>

    <div style="display:<%=show%>">
        <h3>本组请求数据明细</h3>
        <table class="table">
            <tr>
                <th>本组请求成员名</th>
                <th>请求组名</th>
                <th>请求成员民</th>
                <th>请求表名</th>
                <th>是否授权</th>
            </tr>

            <%
                for (int i = 0; i < datas.size(); i++) {

                    String[] colName = ((String) datas.get(i)).split(",");
                    String power;

                    if (!colName[6].equals(account.getUsername())) {
                        System.out.println(account.getUsername());
                        continue;
                    }
                    if ((colName[4].equals("1") && colName[3].equals("1")) || (colName[4].equals("0") && colName[2].equals("1") && colName[3].equals("1"))) {
                        power = "授权";
                    } else {
                        power = "未授权";
                    }

            %>
            <tr>
                <td><%= colName[0]%>
                </td>
                <td><%= colName[7]%>
                </td>
                <td><%= colName[1]%>
                </td>
                <td><%= colName[5]%>
                </td>
                <td><%=power%>
                </td>
            </tr>
            <%}%>
        </table>
    </div>
</div>
<script type="text/javascript">

    $(".sumbit").click(function () {

        var list = "";
        $("span").each(function (i, n) {
            var name = $(this).text();
            console.log(name);
            console.log($("input[name=\"" + name + "\"]:checked").val());
            list = list + $("input[name=\"" + name + "\"]:checked").val() + ",";


        });


        $.ajax({
            type: "post",
            async: true,
            url: "Replay.action",
            data: {
                "list": list,
                "agreeName": "<%=agree%>"
            },
            success: function (result) {
                if (result == 'success') {
                    alert("提交成功");
                    // $(this).css({"display":"none","background":"red"});
                    $(".sumbit").hide();
                    $("input").each(function (i, n) {
                        $(this).attr("disabled", "disabled");
                    });
                    <% session.setAttribute("status","agree");%>
                } else {
                    alert("提交失败");
                }

            }
        });


        console.log(list);

    });


</script>
</body>

</html>